package org.aeon.gamechatnest.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.aeon.gamechatnest.common.response.Result;
import org.aeon.gamechatnest.common.response.ResultBuild;
import org.aeon.gamechatnest.dto.UserVo;
import org.aeon.gamechatnest.service.FriendService;
import org.aeon.gamechatnest.util.SecurityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 好友管理控制器
 *
 * @author : Qik 2024/5/9 17:07
 */
@Validated
@RestController
@RequestMapping("/friend")
@Tag(name = "FriendControllerApi", description = "好友管理控制器类API")
public class FriendController {
    @Autowired
    private FriendService friendService;

    @Operation(
            summary = "同意好友请求",
            description = "同意通过好友请求，新增好友",
            parameters = {@Parameter(name = "id", description = "请求编号id")}
    )
    @PostMapping("/agree")
    public Result agreeFriendRequest(Long id) {
        boolean res = friendService.agree(id);
        return ResultBuild.successIf(res).build();
    }

    @Operation(
            summary = "拒绝好友请求",
            description = "拒绝通过好友请求，新增好友",
            parameters = {@Parameter(name = "id", description = "请求编号id")}
    )
    @PostMapping("/refuse")
    public Result refuseFriendRequest(Long id) {
        boolean res = friendService.refuse(id);
        return ResultBuild.successIf(res).build();
    }

    @Operation(
            summary = "获取全部好友",
            description = "获取全部好友列表"
    )
    @GetMapping("/all")
    public Result allFriendList() {
        List<UserVo> list = friendService.findFriendByUserId(SecurityUtil.getUserId());
        return ResultBuild.result().successful().data(list).build();
    }

    @Operation(
            summary = "获取在线好友",
            description = "获取在线好友列表"
    )
    @GetMapping("/online")
    public Result onlineFriendList() {
        List<UserVo> list = friendService.findOnline(SecurityUtil.getUserId());
        return ResultBuild.result().successful().data(list).build();
    }

    @Operation(
            summary = "删除好友",
            description = "删除当前登录用户的某位好友",
            parameters = {@Parameter(name = "id", description = "好友用户id")}
    )
    @DeleteMapping("/{id}")
    public Result remove(@PathVariable Long id) {
        boolean res = friendService.remove(id);
        return ResultBuild.successIf(res).build();
    }
}
